package au.edu.utas.yu_qiao_group.luckyman.ui.account;

import android.app.AlertDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.io.File;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import au.edu.utas.yu_qiao_group.luckyman.MainActivity;
import au.edu.utas.yu_qiao_group.luckyman.R;
import au.edu.utas.yu_qiao_group.luckyman.service.UserService;

public class AccountFragment extends Fragment {
  private static final String TAG = "AccountFragment";

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
  }

  @Override
  public View onCreateView(@NonNull LayoutInflater inflater,
                           ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_account, container, false);
    SharedPreferences s = getContext().getSharedPreferences(MainActivity.KEY_DATA_PRIVATE, Context.MODE_PRIVATE);
    // set avatar
    ImageView avatarView = rootView.findViewById(R.id.imageView2);
    String avatarFile = UserService.getCurrentUserCompanyAvatar(s);
    if (TextUtils.isEmpty(avatarFile)) {
      avatarView.setImageResource(R.mipmap.ic_launcher);
    } else {
      avatarView.setImageURI(Uri.fromFile(new File(getContext().getExternalFilesDir("my_capture"), avatarFile)));
    }
    TextView companyName = rootView.findViewById(R.id.account_company_name);
    companyName.setText(UserService.getCurrentUserCompany(s));
    TextView companyId = rootView.findViewById(R.id.account_company_id);
    companyId.setText(UserService.getCurrentUserCompanyId(s));
    TextView companyDetails = rootView.findViewById(R.id.account_company_details);
    companyDetails.setText(UserService.getCurrentUserCompanyInfo(s));
    TextView companyContact = rootView.findViewById(R.id.account_company_contact);
    companyContact.setText(UserService.getCurrentUserCompanyContact(s));

    return rootView;
  }

}
